home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / softwareproperties / gtk / DialogCacheOutdated.py < prev    next >
Encoding:
Python Source  |  2009-03-27  |  2.5 KB  |  73 lines

  1. # dialog_cache_outdated.py - inform the user to update the apt cache
  2. #  
  3. #  Copyright (c) 2006 Canonical
  4. #  
  5. #  Authors: 
  6. #       Sebastian Heinlein <sebastian.heinlein@web.de>
  7. #  This program is free software; you can redistribute it and/or 
  8. #  modify it under the terms of the GNU General Public License as 
  9. #  published by the Free Software Foundation; either version 2 of the
  10. #  License, or (at your option) any later version.
  11. #  This program is distributed in the hope that it will be useful,
  12. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #  GNU General Public License for more details.
  15. #  You should have received a copy of the GNU General Public License
  16. #  along with this program; if not, write to the Free Software
  17. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  18. #  USA
  19.  
  20. import os
  21. import subprocess
  22. import thread
  23. import time
  24. import gobject
  25. import gtk
  26. import gtk.glade
  27. import apt_pkg
  28.  
  29. class DialogCacheOutdated:
  30.     def __init__(self, parent, datadir):
  31.         """setup up the gtk dialog"""
  32.         self.parent = parent
  33.  
  34.         if os.path.exists("../data/dialogs.glade"):
  35.             self.gladexml = gtk.glade.XML("../data/dialogs.glade")
  36.         else:
  37.             self.gladexml = gtk.glade.XML("%s/glade/dialogs.glade" % datadir)
  38.         self.dialog = self.gladexml.get_widget("dialog_cache_outofdate")
  39.         self.dialog.set_transient_for(parent)
  40.  
  41.     def update_cache(self, window_id, lock):
  42.         """start synaptic to update the package cache"""
  43.         try:
  44.             apt_pkg.PkgSystemUnLock()
  45.         except SystemError:
  46.             pass
  47.         cmd = ["/usr/sbin/synaptic", "--hide-main-window",
  48.                "--non-interactive",
  49.                "--parent-window-id", "%s" % (window_id),
  50.                "--update-at-startup"]
  51.         subprocess.call(cmd)
  52.         lock.release()
  53.  
  54.     def run(self):
  55.         """run the dialog, and if reload was pressed run synaptic"""
  56.         res = self.dialog.run()
  57.         self.dialog.hide()
  58.         if res == gtk.RESPONSE_APPLY:
  59.             self.parent.set_sensitive(False)
  60.             lock = thread.allocate_lock()
  61.             lock.acquire()
  62.             t = thread.start_new_thread(self.update_cache,
  63.                                        (self.parent.window.xid, lock))
  64.             while lock.locked():
  65.                 while gtk.events_pending():
  66.                     gtk.main_iteration()
  67.                     time.sleep(0.05)
  68.             self.parent.set_sensitive(True)
  69.         return res
  70.